#coding:utf-8
from lovewith.website.models import Link
from lovewith.utils.mtcache import MtCache


class LinkApi:
    def __init__(self):
        pass

    #获取推荐的友情链接
    @staticmethod
    def get_recommand():
        link_data = MtCache('link').get()

        if not link_data:
            link_data = []
            link_filter_data = Link.objects.all().order_by('-sort')[0:18]
            for link in link_filter_data:
                link_data.append({'name': link.site_name, 'url': link.site_url})

            MtCache('link').set(link_data)

        return link_data

    #获取全部连接
    @staticmethod
    def get_all():
        return Link.objects.all().order_by('-sort')